//本js文件用于操作授权
//author:quanxiwei
//date:20090714
//comment:

//给用户权限
function changeUserAuth(userId, roleId) {
	var isChecked = 0;
	if ($("#checkbox_" + roleId).attr("checked") === true) {
		isChecked = 1;
	}
	var url = "user!changeAuth.action";
	ajaxRequest(url, userId, roleId, isChecked, 1);
}
//改变角色的权限
function changeRoleAuth(roleId, authId) {
	var isChecked = 0;
	if ($("#checkbox_" + authId).attr("checked") === true) {
		isChecked = 1;
	}
	var url = "role!changeAuth.action";
	ajaxRequest(url, roleId, authId, isChecked, 0);
}
//绑定资源和权限
function changeRescAuth(rescId, authId) {
	var isChecked = 0;
	if ($("#checkbox_" + authId).attr("checked") === true) {
		isChecked = 1;
	}
	var url = "resc!changeAuth.action";
	ajaxRequest(url, rescId, authId, isChecked, 0);
}

//执行ajax请求，更改权限
function ajaxRequest(url_val, obId, opId, isChecked, type) {
	$.ajax({url:url_val, data:{obId:obId, opId:opId, check:isChecked}, cache:false, dataType:"json", error:function () {
		alert("error:\u64cd\u4f5c\u5931\u8d25\uff01");
	}, success:function (result) {
		ajaxCallBack(type, opId, result);
	}});
}

//ajax回调方法
function ajaxCallBack(type, opId, result) {
	if (type == 1) {
		$("#ecTable").find("input:checkbox").each(function () {
			$(this).attr("checked", "");
		});
	}
	if (result === 0) {
		$("#checkbox_" + opId).attr("checked", "");
	}
	if (result === 1) {
		$("#checkbox_" + opId).attr("checked", true);
	}
}

